﻿using MinoChat.Ui.Enums;
using System.Globalization;
using System.Windows.Data;

namespace MinoChat.Ui.Converters;
// 将图标枚举转换为Unicode字符的转换器
public class IconToUnicodeConverter : IValueConverter
{
    // 枚举到Unicode的映射字典
    private static readonly Dictionary<IconType, int> IconMap = new()
    {
        { IconType.None, 0 },
        { IconType.DownLoad, 0xe608 },
        { IconType.Refresh, 0xe619 },
        { IconType.Share, 0xe620 },
        { IconType.NewChat, 0xe64c },
        { IconType.Setting, 0xe643 },
        { IconType.Search, 0xe600 },
        { IconType.Mask, 0xe751 },
        { IconType.Send, 0xe656 },
        { IconType.Voice, 0xe602 },
        { IconType.Running, 0xe60d },
        { IconType.Close, 0xe685 },
        { IconType.Clear, 0xe6e7 },
        { IconType.UploadFile, 0xe621 },
        { IconType.Models, 0xe63f },
        { IconType.ShortCut, 0xe633 },
        { IconType.McpTool, 0xe726 },
        { IconType.Terminal, 0xe63b },
        { IconType.UploadImage, 0xe634 },
        { IconType.Home, 0xe622 },
        { IconType.Edit, 0xe716 },
        { IconType.About, 0xe771 },
        { IconType.Close2, 0xe603 },
        { IconType.Parameter, 0xe60a },
        { IconType.Url, 0xe82e },
        { IconType.Copy, 0xeac1 },
        { IconType.Key, 0xe635 },
        { IconType.Delete, 0xe6b5 },
        { IconType.Provider, 0xe944 },
        { IconType.Config, 0xe7e7 },
        { IconType.Quote, 0xec81 },
        { IconType.Train, 0xe628 },
        { IconType.Fine, 0xe604 },
        { IconType.Theme, 0xeaec }
    };
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is IconType iconType && iconType != IconType.None)
        {
            if (IconMap.TryGetValue(iconType, out var unicodeValue))
            {
                //将一个 32位的Unicode码点（一个整数）转换为它对应的字符串（string）
                return char.ConvertFromUtf32(unicodeValue);
            }
        }
        return string.Empty;
    }
    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
